#ifndef Document_First
#define Document_First
#ifdef __GNUG__
#pragma interface
#endif

#include "Manager.h"
#include "Symbol.h"

class FileDialog;
class VObject;

enum FileDialogType {
	eFDTypeRead,
	eFDTypeWrite,
	eFDTypeImport
};

extern const Symbol cDocTypeUndef; // "UNDEF" document type

//---- Document ----------------------------------------------------------------

class Document : public Manager {
public:
	MetaDef(Document);

	Document(const Symbol &documentType= cDocTypeUndef);
	~Document();

	//---- dialogs
	virtual FileDialog *MakeFileDialog(FileDialogType);

	//---- document attributes
	u_long UniqueId();
	const Symbol &GetDocumentType();
	bool IsUntitled();
	bool IsConverted();
	const char *GetBaseName();
	void SetData(Data *fd);
	Data *GetData()
		{ return docData; }

	//---- change management
	virtual CommandProcessor *MakeCmdProcessor();
	virtual bool Modified();
	virtual bool SavedChanges();

	//---- misc
	void CollectParts(Collection*);
	void ExtCommand(int from, char *req, char *args, int len,
					char *&ret, int &retlen);
	//---- windows
	VObject *DoMakeIconContent();

	//---- menues
	virtual MenuBar *DoMakeMenuBar();
	Menu *MakeMenu(int menuId);
	void DoSetupMenu(Menu*);
	Command *DoMenuCommand(int);

	//---- loading
	virtual bool CanLoad(Data *data);
	virtual void AboutToLoad(Data *data);
	virtual bool LoadData(Data *data, bool unique);

	//---- generic menu commands
	virtual bool Close();       // return TRUE if OK
	virtual void Revert();
	virtual bool Save();        // return TRUE if OK
	virtual bool SaveAs();      // return TRUE if OK

	//---- input/output
	virtual bool DoFileIsAlreadyOpen(Document *shown, const char *name);
	virtual bool DoReadData(Data *data);        // return TRUE if OK
	virtual bool DoRead(IStream&, Data *data);  // return TRUE if OK
	virtual bool DoWrite(OStream&, Data *data); // return TRUE if OK
	virtual Object *ReturnObjectToStore();
	virtual void Store();
	virtual long SizeHintForWriting();

	//---- obsolete
	virtual VObject *DoMakeIcon(const char *name);
	virtual bool Load(const char *filename= 0, bool unique= TRUE);

private:
	Symbol docType;
	Data *docData;
};

inline const Symbol &Document::GetDocumentType()
	{ return docType; }

#endif

